from datetime import datetime

from app import db


class User(db.Model):
    __tablename__ = 'user'
    user_id = db.Column(db.Integer, primary_key=True)
    user_name = db.Column(db.String(100),  nullable=False)
    password = db.Column(db.String(100), nullable=False)
    phone = db.Column(db.String(20))
    email = db.Column(db.String(100))
    ip = db.Column(db.String(100), nullable=False)
    avatar_url = db.Column(db.String(100), nullable=False)


# 定义 Dataset 模型
class Dataset(db.Model):
    __tablename__ = 'dataset'
    dataset_id = db.Column(db.Integer, primary_key=True)
    dataset_name = db.Column(db.String(100), nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.user_id'), nullable=False)
    size = db.Column(db.Integer)
    dataset_address = db.Column(db.String(200), nullable=False)
    dataset_describe = db.Column(db.Text, nullable=False)
    dataset_time = db.Column(db.DateTime, default=datetime.utcnow)
    dataset_use = db.Column(db.Integer, default=0)
    dataset_state = db.Column(db.String(80), default='private')


# 定义 Model 模型
class Model(db.Model):
    __tablename__ = 'model'
    model_id = db.Column(db.Integer, primary_key=True)
    model_name = db.Column(db.String(200), nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.user_id'), nullable=False)
    model_describe = db.Column(db.Text)
    model_use = db.Column(db.Integer, default=0)
    model_protect = db.Column(db.String(80), nullable=False)
    model_type = db.Column(db.String(80), nullable=False)
    model_state = db.Column(db.String(80), default='private')
    # public private deleted


# 定义 Apply 模型
class Apply(db.Model):
    __tablename__ = 'apply'
    apply_id = db.Column(db.Integer, primary_key=True)
    applicant_id = db.Column(db.Integer, db.ForeignKey('user.user_id'), nullable=False)
    checker_id = db.Column(db.Integer, db.ForeignKey('user.user_id'), nullable=False)
    dataset_id = db.Column(db.Integer, db.ForeignKey('dataset.dataset_id'), nullable=False)
    apply_describe = db.Column(db.Text)
    expiration_time = db.Column(db.DateTime)
    apply_state = db.Column(db.String(80), default='waiting')


# 定义 Project 模型
class Project(db.Model):
    __tablename__ = 'project'
    project_id = db.Column(db.Integer, primary_key=True)
    project_name = db.Column(db.String(80), nullable=False)
    project_description = db.Column(db.Text)
    starter_id = db.Column(db.Integer, db.ForeignKey('user.user_id'), nullable=False)
    cooperator_id_list = db.Column(db.String(1000))
    project_time = db.Column(db.DateTime, default=datetime.utcnow)
    project_type = db.Column(db.String(80), nullable=False)
    project_model = db.Column(db.String(1000))
    project_state = db.Column(db.String(80), nullable=False)